
import React, {Component} from 'react'
import { requireNativeComponent , StyleSheet, View, TouchableOpacity, Text, NativeEventEmitter, NativeModules} from 'react-native'
import { YellowBox } from 'react-native';
// iOS 本地的模块
var RNHomePage = requireNativeComponent('RNHomePage', HomePage);
// OC 本地导出的模块
var RNBridgeModule = NativeModules.RNNotificationBridgeModule;
// OC 的通知和RN的通知统一
var myNativeEvt = new NativeEventEmitter(RNBridgeModule);
export default class HomePage extends Component {

    constructor(props){
        super(props);
        console.log(props);
        this.props.navigation.setParams({ hideTabBar: false})
        
        this.logoutlistener =  myNativeEvt.addListener('LOGIN_OUT', this._logout)
        this.tabbarShowlistener =  myNativeEvt.addListener('TABBAR_SHOW',this._showTab)
        this.tabbarHiddenlistener = myNativeEvt.addListener('TABBAR_HIDDEN',this._hiddenTab)   
    }
    componentDidMount(){
 
    }
    componentWillUnmount(){
       console.log('homepage unmount')
       this.logoutlistener.remove()
       this.tabbarShowlistener.remove()
       this.tabbarHiddenlistener.remove()
    }

    static navigationOptions = ({navigation}) => ({
    
        tabBarVisible: (navigation.state.params && navigation.state.params.hideTabBar) === false,
        animationEnabled: true
    })
    

    render(){
        return <View style={{flex: 1,backgroundColor: 'rgb(36,144,268)'}}
        >
            <RNHomePage style = {styles.container}/>
        </View> 
    }
    _hiddenTab = () =>{
        this.props.navigation.setParams({ hideTabBar: true })
    }
    _showTab = () => {
        this.props.navigation.setParams({ hideTabBar: false})
    }
    _logout = () => {
        this.props.navigation.navigate('login')
        this.logoutlistener.remove()
        this.tabbarShowlistener.remove()
        this.tabbarHiddenlistener.remove()
    }
}

const styles = StyleSheet.create({
    container :{
        flex : 1,
        marginTop:20,
        backgroundColor : 'red'
    }
})

YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated']);
